
/**		
 * 
 *	uk.co.lmfm.guppy.view.components.settings.AutoSetupPopup
 *	
 *	@version 1.00 | Feb 2, 2010
 *	@author Justin Windle
 *  
 **/
 
package uk.co.lmfm.guppy.view.components.settings 
{
	import flash.events.Event;

	import com.bit101.components.ProgressBar;

	import uk.co.lmfm.guppy.view.components.core.PopupView;

	import com.bit101.components.Text;

	import flash.display.Sprite;

	/**
	 * AutoSetupPopup
	 */
	public class AutoSetupPopup extends PopupView 
	{
		//	----------------------------------------------------------------
		//	PRIVATE MEMBERS
		//	----------------------------------------------------------------

		private var _content : Sprite = new Sprite();
		private var _info : Text = new Text();
		private var _targetProgress : Number = 0.0;		private var _progressEase : Number = 0.01;
		private var _progressBar : ProgressBar = new ProgressBar();

		//	----------------------------------------------------------------
		//	CONSTRUCTOR
		//	----------------------------------------------------------------

		public function AutoSetupPopup()
		{
			_info.text = "Auto setup will attempt to detect your required applications, username and workspace location...";
			_info.width = 220;
			_info.height = 40;
			
			_progressBar.width = 220;
			_progressBar.y = _info.height + 10;
			
			_content.addChild(_info);			_content.addChild(_progressBar);
			
			super("Auto setup in progress", _content, "Cancel Auto Setup", null, false);
		}

		//	----------------------------------------------------------------
		//	PUBLIC METHODS
		//	----------------------------------------------------------------

		override public function show() : void
		{
			super.show();
			
			addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
		}

		override public function hide() : void
		{
			super.hide();
			
			_progressEase = 0.01;
			_progressBar.value = _targetProgress = 0.0;
			removeEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
		}

		//	----------------------------------------------------------------
		//	EVENT LISTENERS
		//	----------------------------------------------------------------

		private function onEnterFrameHandler(event : Event) : void
		{
			//_targetProgress += Math.random() * 0.0005;
			_progressBar.value += (_targetProgress - _progressBar.value) * _progressEase;
			if(_progressBar.value >= 0.999999) hide();
		}

		//	----------------------------------------------------------------
		//	PUBLIC ACCESSORS
		//	----------------------------------------------------------------

		public function get progress() : Number
		{
			return _targetProgress;
		}

		public function set progress(value : Number) : void
		{
			_targetProgress = value;
			if(_targetProgress >= 0.99) _progressEase = 0.5;
		}
	}
}
